<table width="100%" border="1" rules="all" cellspacing="0" cellpadding="0" class="tblSort" id="tbl_qry_fac">
<thead>
  <tr>
    <th>Periodo</th>
    <th>Facturado en Venta</th>
    <th>Fact. en Costo</th>
    <th>Utilidad Venta</th>
  </tr>
  </thead>
  <tbody>
  <?php 
include('../../Connections/KRAPPERCON.php');
$tienda = $_POST['cb_local'];
$inicio = $_POST['inicio'];
$final = $_POST['final'];
if ($tienda==""){
$tienda = "0";
}
$grp = $_POST['group'];
//$grp = 0;
$sql = "call sp_consultaUtilidad (".$tienda.",'".$inicio."','".$final."',".$grp.")";
//echo $sql;
$res = $mysqli->query($sql);
$v = 0;
$c = 0;
$u = 0;
if($res){
	while($row = $res->fetch_assoc()){
	$venta =  $row['venta'];
	$costo =  $row['costo'];
	$util = $venta - $costo;
	$v+=$venta;
	$c+=$costo;
	$u+=$util;
	?>
    <tr>
    <td><?php echo $row['periodo'];?></td>
    <td class="qt"><?php echo $venta; ?></td>
    <td class="qt"><?php echo $costo; ?></td>
    <td class="qt"><?php echo $util;?></td>            
    </tr>
    <?php 
	}
$res->close();
$mysqli->chechk_result();
}
?>
</tbody>
<tfoot>
<tr><th>Total</th>
<th class="qt"><?php echo $v;?></th>
<th class="qt"><?php echo $c;?></th>
<th class="qt"><?php echo $u;?></th>
</tr>
</tfoot>
</table>